package org.example.im.common.serialize.impl;

import com.alibaba.fastjson.JSON;
import org.example.im.common.serialize.Serializer;
import org.example.im.common.serialize.SerializerType;
import org.springframework.stereotype.Component;

/**
 * @author dingrui
 * @since 2022/2/10
 * @description
 */
@Component
public class JsonSerializer implements Serializer {

    @Override
    public SerializerType type() {
        return SerializerType.JSON;
    }

    @Override
    public byte[] serialize(Object o) {
        return JSON.toJSONBytes(o);
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> clazz) {
        return JSON.parseObject(bytes, clazz);
    }
}
